package com.youle.exceptionhandler;

import com.youle.exception.ExceptionResponse;
import com.youle.exception.YLException;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * Created by
 *
 * @author touni
 * @date 2019/4/18
 * @time 12:28
 */
@ControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(RuntimeException.class)
    public ResponseEntity<ExceptionResponse> handlerRuntimeException(YLException e){
        ExceptionResponse exceptionResponse = new ExceptionResponse(e.getExceptionEnum());
        return ResponseEntity.status(exceptionResponse.getCode()).body(exceptionResponse);

    }



}
